package com.shenzhen.horselive.ui.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.flqy.baselibrary.utils.L;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.adapter.MyTeanAdapter;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.beans.MyTeamBean;
import com.shenzhen.horselive.databinding.ActivityMyTeamBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.LoadingViewObserver;
import com.shenzhen.horselive.utils.A;

public class MyTeamActivity extends AppBarActivity {

    ActivityMyTeamBinding  binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding =ActivityMyTeamBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setStyleDark();
        setTitle("我的团队");
        initViews();
        iniData();
    }

    private void iniData() {
        ApiFactory.getApiService().myteam(User.get().getMyInfo().getToken())
                .compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<MyTeamBean>(this) {
                    @Override
                    protected void onNextInActive(MyTeamBean myTeamBean) {
                        if (myTeamBean.isSuccess())
                        {
                            adapter.setNewInstance(myTeamBean.getData().getUserDirectTeam());
                            //跟新
                            binding.tvLevel.setText(myTeamBean.getData().getCurrentUserGradeName());

                            binding.tvTeamNum.setText(String.format("团队人数：%s人",myTeamBean.getData().getTeamCount()+""));

                            binding.tvTeamYeji.setText("团队业绩："+myTeamBean.getData().getTeamPerformance());

                            binding.tvApplyNum.setText("已预约："+myTeamBean.getData().getReservedCount()+"人");
                            binding.tvOpenedNum.setText("已开卡："+myTeamBean.getData().getOpenCardCount()+"人");


                        }else
                        {
                            showToast(myTeamBean.getErrMessage());
                        }
                    }
                });

    }


    MyTeanAdapter  adapter;
    private void initViews() {
        adapter = new MyTeanAdapter(R.layout.item_myteam);
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(this));
        binding.recyclerview.setAdapter(adapter);

       adapter.setOnItemClickListener(new OnItemClickListener() {
           @Override
           public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
               DirectPushDetailsActivity.start(getContext(),MyTeamActivity.this.adapter.getItem(position).getGrade()+"");
           }
       });

    }
}